/**
 * Copyright (c) 2010 - 2012,  Inc. All rights reserved.
 * @fileoverview   添加到组
 * @author bowen liu | liubowen082@163.com
 * @version 1.1 | 2013-4-13
 * @example
 * {uploadBox // 容器名}
 */

$require('mod.cPrompt');
LJS.define('cpt.addUserList',function(ljs){
	
	var addUserList = {
		showAdd:function(ids){
			var that = this;
			if(this.lay){
				this.lay.show();
				return
				}
			var arr = ['<select node_type="select0">']
			
			$.each(JAJU.userGroup,function(i,a){
					arr.push('<option value="'+a.id+'">'+a.name+'</option>')
				});
			arr.push('</select>')
			
			this.lay = new ljs.mod.cPrompt({
				txt:'<ul>\
                    <li class="fillTxt"><div class="tit">&nbsp;</div><span class="tit01">已选择<span class="colorRem">'+ids.length+'</span> 人，添加到：</span>'
                +arr.join('')+
				'</li>\
                </ul>'
			});
			this.lay.show();
			$('[event_type="ok"]',this.lay.win).on('click',function(e){
				that.post(ids);
				return false;
			})
			},
		post:function(ids){
			$('[node_type="error"]',$(this.lay.win)).hide()
			var data = this.check(),that = this;
			
			if(!data){
				$('[node_type="error"]',$(that.lay.win)).show().find('.colorRem').html('请完整填写信息')
				return 
				}
			$.ajax({
			  type: "post",
			  url: "user_addtogroup",
			  dataType: "json",
			  data:{ids:ids.join(','),id:data},
			  cache:false,
			  success:function(json){
				  if(json.status=='100000'){
					  window.location.reload();
				  }else if(json.status=='100003'){
                	window.location.href = json.content.url;
                }else{
					  $('[node_type="error"]',$(that.lay.win)).show().find('.colorRem').html(json.msg)
					  }
			  }
			});
			},
		check:function(){
			if(!this.lay){
				return
				}
			var id = $('[node_type="select0"] option:selected',$(this.lay.win)).attr('value');
			
			if(!id){
				return false
				}
			return id
			}
		}

    return addUserList;
    
});
